
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>房间管理</title>
    <link rel="stylesheet" href="../../../layui/css/layui.css">
    <script src="../../../layui/layui.js"></script>
</head>
<style type="text/css">
    body{
        height: 100%;
        width: 100%;
        margin-top: 11px;
    }


</style>

<body >
<!-- 内容主体区域 -->
<div class="layui-fluid layui-form">
    <div class="layui-form-item">
        <div class="layui-input-inline " style=" width: 638px;">
            <button class="layui-btn layui-btn-normal addMember">新增房间</button>
            <!--<button class="layui-btn updateMember">修改顾客</button>-->
            <button class="layui-btn layui-btn-danger deleteMember">删除房间</button>
            <!--      <button class="layui-btn">默认按钮</button>
                  <button class="layui-btn layui-btn-normal">百搭按钮</button>-->
        </div>
        <div class="layui-inline" id="salonList">
            <label class="layui-form-label">选择门店</label>
            <div class="layui-input-inline">
                <select name="modules"  lay-search="" class="userKey">
                </select>
            </div>
        </div>
        <!--<div class="layui-inline">-->
            <!--<div class="layui-input-inline">-->
                <!--<input type="text" name="userKey" class="layui-input userKeyValue ">-->
            <!--</div>-->
            <!--<div class="layui-input-inline">-->
                <!--<button class="layui-btn layuiadmin-btn-admin layui-btn-normal check" lay-submit="" lay-filter="LAY-user-back-search">-->
                    <!--<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>-->
                <!--</button></div>-->
        <!--</div>-->
    </div>
</div>

<div id="pTable" >
    <table id="layui_table_id" class="layui-table" lay-skin="line" lay-filter="test" style="width: 1680px">

    </table>
    <!--  <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
      </script>-->
    <div id="laypage"></div>
</div>
</body>
</html>

<script type="text/javascript">

    //重新渲染表单
    function renderForm(){

        layui.use('form', function(){

            var form = layui.form;
            form.render();

        });

    }
    layui.use(['form','laydate','layer','table','laypage','util'],function(){
        var form = layui.form;
        var laydate=layui.laydate;
        var $ = layui.$;
        productsearch(1);


        var url = '/hy/basic/stuff/checkYuanZhang';
        $.ajax({
            type:'POST',
            url:url,
            dataType:"json",
            success: function(data){
                var dataJson=JSON.stringify(data);

                console.log("+++"+JSON.stringify(data));
                console.log(data.data);
                if(data.data.msgcode == '0'){
                    $("#salonList").show();
                }else{
                    $("#salonList").hide();

                }

                renderForm();
            },
            error:function(data){
                alert("操作失败");
                console.log(data);
            }
        })

        function productsearch(page,filterExpr) {

            var table = layui.table,
                laydate = layui.laydate,
                laypage = layui.laypage;
            var form = layui.form;
            table.render({
                elem : '#layui_table_id',
                url : '/hy/basic/storeRoom/getStoreRoom',
                cols : [ [
                    {checkbox: true,
                        filter:'test'
                    }
                    ,
                    {
                        field : 'recordId',
                        title : 'id',
                        sort : true,
                        align : 'center'
                    }
                    ,  {
                        field : 'roomName',
                        title : '房间名',
                        align : 'center'
                    }



                ] ],
                page : true,
                where : {
                    filterExpr:filterExpr,
                },
                responseHandler: function (res, curr,count) {
                    $('#pageNum').val(curr);
                    return {
                        "count": res.total,
                        "data": res.data,
                        "code": 0,//code值为200表示成功
                        "msg": ""
                    }
                },
                done : function(res, curr, count) {
                    console.log(res)
                    $('#pageNum').val(curr);

                }
            })
            // table.on('checkbox(test)', function(obj){
            //   console.log(layui.table.checkStatus('layui_table_id'));
            // });
            // 监听工具条
            table.on('tool(test)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data, //获得当前行数据
                    layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent == 'detail') {
                    queryById(data.id);
                } else if (layEvent == 'del') {
                    //alert(data.id)
                    var pageNum = $('#pageNum').val();
                    layer.confirm('真的删除行么', function(index){
                        deleteById(data.id);
                        layer.close(index);
                        //向服务端发送删除指令
                    });
                } else if (layEvent === 'edit') {
                    layer.msg('编辑操作');
                }
            });
            //常规用法
            laydate.render({
                elem : '#initialStoreId'
            });
            //常规用法
            laydate.render({
                elem : '#processingTime'
            });

        }

        $(".check").on("click", function() {

            var userKey=$('.userKey option:selected').val();
            if(userKey!=""){
                var userKeyValue = $('.userKeyValue').val();
                var temp = userKey+"='"+userKeyValue+"'";
                productsearch(1, temp);
            }else{
                productsearch(1);
            }

        })
        $(".tingzhi").on("click",function(){
            var data = layui.table.checkStatus('layui_table_id').data;
            if(data.length>1||data.length<1){
                alert("请选中一条数据");
                return false;
            }
            $.ajax({
                type:'POST',
                url:'/admin/systemUsers/disableUser.handler',
                data: {userId:data[0].recordId},
                success: function(data){
                    alert("操作成功！");
                    productsearch(1);
                },
                error:function(data){
                    alert("操作失败");
                    console.log(data);
                }
            })
        })


        $(".qidong").on("click",function(){
            var data = layui.table.checkStatus('layui_table_id').data;
            if(data.length>1||data.length<1){
                alert("请选中一条数据");
                return false;
            }
            $.ajax({
                type:'POST',
                url:'/admin/systemUsers/enableUser.handler',
                data: {userId:data[0].recordId},
                success: function(data){
                    alert("操作成功！");
                    productsearch(1);
                },
                error:function(data){
                    alert("操作失败");
                    console.log(data);
                }
            })
        })
        $(".shouquan").on("click",function(){
            var data = layui.table.checkStatus('layui_table_id').data;
            if(data.length<1){
                alert("请选中一条数据");
                return false;
            }
            layer.open({
                type:2,
                area:[482+'px',315+'px'],
                fix:false,
                offset: '80px',
                maxmin:true,
                shadeClose:true,
                scrollbar: false,
                shade:0.4,
                title:'授权',
                content:['authorize.html'],
                success:function(layero,index){
                    var iframe = window['layui-layer-iframe' + index];
                    // 向子页面的全局函数child传参
                    iframe.child(data[0]);
                    console.log("成功");
                },
                fail:function(data){
                    console.log(data);
                }
            })
        })


        $(".deleteMember").on("click",function(){
            var data = layui.table.checkStatus('layui_table_id').data;
            if(data.length<1){
                alert("请选中一条数据");
                return false;
            }
            var deleteList = [];
            for(var i=0 ;i<data.length;i++){
                var id = data[i].recordId;
                var temp =id+"";
                deleteList.push(temp);
            }
            console.log(deleteList);
            $.ajax({
                type:'POST',
                url:'/hy/basic/storeRoom/deleteRoomForPc',
                data: JSON.stringify(deleteList),
                contentType: "application/json",
                success: function(data){
                    alert("操作成功！");
                    productsearch(1);
                    // window.parent.location.reload(); //刷新父页面
                    // var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    //parent.layer.close(index);  // 关闭layer

                },
                error:function(data){
                    alert("操作失败");
                    console.log(data);
                }
            })

        })

        $(".addMember").on("click",function(){
            layer.open({
                type:2,
                //area:[482+'px',355+'px'],
                area:[600+'px',400+'px'],
                fix:false,
                offset: '80px',
                maxmin:true,
                shadeClose:true,
                scrollbar: false,
                shade:0.4,
                title:'新增房间',
                content:['add_room.html'],
                success:function(layero,index){
                    console.log("成功");
                },
                fail:function(data){
                    console.log(data);
                }
            })
        })
        $(".updateMember").on("click",function(){
            console.log(layui.table.checkStatus('layui_table_id'));
            var data = layui.table.checkStatus('layui_table_id').data;
            if(data.length>1){
                alert("请选中一条数据");
                return false;
            }
            layer.open({
                type:2,
                //area:[482+'px',315+'px'],
                area:[600+'px',400+'px'],
                fix:false,
                offset: '80px',
                maxmin:true,
                shadeClose:true,
                scrollbar: false,
                shade:0.4,
                title:'修改用户',
                content:['add_member.html'],
                success:function(layero,index){
                    // 获取子页面的iframe
                    var iframe = window['layui-layer-iframe' + index];
                    // 向子页面的全局函数child传参
                    iframe.child(data[0]);
                    console.log("成功");
                },
                fail:function(data){
                    console.log(data);
                }
            })
        })

    });
    function gender(t){
        if(t==0){
            return '男';
        }else{
            return '女';
        }
        //return util.toDateString(t);
    };
    function memberGradeId(t){
        if(t==0){
            return 'A类';
        }else if(t==1){
            return 'B类';
        }else if(t==2){
            return 'C类';
        }else{
            return 'D类';
        }
    }
</script>
<script type="text/html" id="gender">
    {{ gender(d.gender) }}
</script>
<script type="text/html" id="memberGradeId">
    {{ memberGradeId(d.memberGradeId) }}
</script>